/*
 *
 *  Copyright (C) 2012-2024
 *  All rights reserved, Designed By 杭州连线客信息技术有限公司
 *  注意：
 *  本软件为杭州连线客信息技术有限公司开发研制，未经购买不得使用
 *  购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
 *  一经发现盗用、分享等行为，将追究法律责任，后果自负
 *
 */

package com.lxk.oms.flow.confirm;

import com.lxk.oms.order.domain.req.ConfirmOrderReq;
import com.lxk.oms.order.domain.vo.OmsOrderVo;
import com.lxk.oms.order.service.IOmsOrderService;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.log.LFLog;
import com.yomahub.liteflow.log.LFLoggerManager;
import lombok.AllArgsConstructor;
import org.dromara.common.core.utils.ValidationUtils;

import static com.lxk.oms.flow.confirm.FlowConfirmOrderNodeConst.FILL_ORDER_NODE;

/**
 * 填充对应的上下文
 *
 * @author heyi
 * 2024/9/3
 */
@AllArgsConstructor
@LiteflowComponent(FILL_ORDER_NODE)
public class OrderFillNode extends NodeComponent {
    private final IOmsOrderService omsOrderService;
    private final LFLog log = LFLoggerManager.getLogger(FlowExecutor.class);

    @Override
    public void beforeProcess() {
        ConfirmOrderReq request = this.getRequestData();
        ValidationUtils.validate(request);
        log.info("confirmOrderNode beforeProcess,{}", request);
    }

    @Override
    public void process() throws Exception {
        ConfirmOrderReq request = this.getRequestData();
        ConfirmOrderContext contextBean = this.getContextBean(ConfirmOrderContext.class);
        Long userId = request.getUserId();
        String orderNo = request.getOrderNo();
        OmsOrderVo omsOrderVo = omsOrderService.queryByOrderSn(orderNo, userId);
        contextBean.setOmsOrderVo(omsOrderVo);
        contextBean.setUserId(userId);
        contextBean.setUserType(request.getUserType());
        contextBean.setOrderSn(orderNo);
        contextBean.setSendOptionEvent(request.getSendOptionEvent());
        ValidationUtils.validate(contextBean);
    }
}
